package cn.yuan.xiaoyu.newsmodule.adapter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import java.util.List;

/**
 * Created by yukuoyuan on 2017/3/7.
 * 这是一个新闻主页面的适配器
 */

public class NewsHomePagerAdapter extends FragmentPagerAdapter {
    private List<Fragment> fragments;
    private List<String> list;

    public NewsHomePagerAdapter(FragmentManager fm, List<Fragment> fragments, List<String> list) {
        super(fm);
        this.fragments = fragments;
        this.list = list;
    }

    @Override
    public Fragment getItem(int position) {
        return fragments.get(position);
    }

    @Override
    public int getCount() {
        return fragments.size();
    }

    //此方法用来显示tab上的名字
    @Override
    public CharSequence getPageTitle(int position) {
        return list.get(position % list.size());
    }
}
